var memberinfoconfig_userinfo;
function btnSubmit(param){
    if(param == "save"){

        var formdata = $("#memberinfocconfig_frm_main").serializeObject();
        console.log('submit member info:')
        console.log(formdata);
        if(server.isEmpty(formdata.province)||server.isEmpty(formdata.city)||server.isEmpty(formdata.area)){
            pop_up("请输入出生地址");
            return;
        }
        if(server.isEmpty(formdata.agree)){
            pop_up("请同意《会员服务协议》");
            return;
        }
        server.req('wechat/member/update',formdata,function (e) {
            server.removeUser();
            server.loadindex('page/user/user');
        },null,"POST");


    }else if(param == "cancel"){
        server.loadindex('page/user/user');
    }
};
//获取当前用户资料
server.getUserInfo(function (res) {
    console.log(res)
    memberinfoconfig_userinfo=res;
    server.loadData(".content-body",res);
    if(res.sex==1){
        console.log("nan")
        $("#nan").css("background-color","#dcdcdc");
    }
    else if(res.sex==0){
        console.log("nv")
        $("#nv").css("background-color","#dcdcdc");
    }

});
//选择地区
Area.init("#area_province","#area_city","#area_area");

//点击上传文件
$(".uploadclass").change(function(e){
    $(this).upload({
        url:server.url+'/file/uploadFile',
        fileName:'file',

        onsuccess:function(r){
            $("#"+e.currentTarget.dataset.id).attr("src",r.data.url);
            $("#"+e.currentTarget.dataset.r).val(r.data.url);

        },

        onerror:function(e){
            console.log(e)
        },
        oncomplate:function(data){
            console.log(data);
        }
    });
});
//性别选择
function selectSex(sex) {
    if(sex==1){
        $("#nan").css("background-color","#dcdcdc");
        $("#nv").css("background-color","#ffffff");
        $("#sex").val(1);
    }else if(sex==0){
        $("#nan").css("background-color","#ffffff");
        $("#nv").css("background-color","#dcdcdc");
        $("#sex").val(0);
    }
}

//会员协议
function toagree(key) {
    server.loadindex('page/agree/agree','key='+key);
}